<?php

if_get('/raw_addresses/update/*', function ($raw_address_id)
{
    $raw_address = dao('raw_address')->find($raw_address_id);
    otherwise($raw_address->is_not_null(), 'raw_address not found');

    return render('raw_address/update', [
        'raw_address' => $raw_address,
    ]);
});

if_post('/raw_addresses/update/*', function ($raw_address_id)
{
    $raw_address = dao('raw_address')->find($raw_address_id);
    otherwise($raw_address->is_not_null(), 'raw_address not found');

    $raw_address->number = input('number');
    $raw_address->person_name = input('person_name');
    $raw_address->person_mobile_number = input('person_mobile_number');
    $raw_address->estate_name = input('estate_name');
    $raw_address->house_address = input('house_address');
    $raw_address->status = input('status');
    $raw_address->snap_formated_address_string = input('snap_formated_address_string');
    $raw_address->upload_batch_id = input('upload_batch_id');

    return redirect('/upload_batches/detail/'.$raw_address->upload_batch_id);
});

if_post('/raw_addresses/delete/*', function ($raw_address_id)
{
    $raw_address = dao('raw_address')->find($raw_address_id);
    otherwise($raw_address->is_not_null(), 'raw_address not found');

    $raw_address->delete();

    return redirect('/upload_batches/detail/'.$raw_address->upload_batch_id);
});
